package com.wjw.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wjw.entity.Carousel;
import com.wjw.dao.CarouselMapper;

/**
 * @author WuJianWei
 * @date 2022/2/28 19:59
 */
@Service
public class CarouselService extends ServiceImpl<CarouselMapper, Carousel> {
    @Autowired
    private RedisTemplate redisTemplate;

    public List<Carousel> getCarousel() {
        Map<Object, Object> carousel = redisTemplate.opsForHash().entries("carousel");
        if (carousel.isEmpty()) {
            List<Carousel> carouselList = baseMapper.selectList(null);
                    carousel.put("carousel", carouselList);
            redisTemplate.opsForHash().putAll("carousel", carousel);
        }
        return (List<Carousel>) carousel.get("carousel");
    }
}

